//
//  ScoreLabelSystem.cpp
//  Tetris
//
//  Created by Jeppe Nielsen on 4/7/14.
//  Copyright (c) 2014 Jeppe Nielsen. All rights reserved.
//

#include "ScoreLabelSystem.hpp"
#include <sstream>

void ScoreLabelSystem::Initialize() {
    AddComponent<Score>();
    AddComponent<Label>();
}

void ScoreLabelSystem::ObjectAdded(Nano::GameObject *object) {
    object->GetComponent<Score>()->Points.Changed += event_handler(this, &ScoreLabelSystem::ScoreChanged, object);
}

void ScoreLabelSystem::ObjectRemoved(Nano::GameObject *object) {
    object->GetComponent<Score>()->Points.Changed -= event_handler(this, &ScoreLabelSystem::ScoreChanged, object);
}

void ScoreLabelSystem::ScoreChanged(Score *score, GameObject* object) {
    std::stringstream s;
    s<<score->Points();
    Label* label = object->GetComponent<Label>();
    label->Text = s.str();
}